package demoMod.invincibleOne.powers;

import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.animations.VFXAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.actions.common.RemoveSpecificPowerAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.ImageMaster;
import com.megacrit.cardcrawl.localization.PowerStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.AbstractPower;
import com.megacrit.cardcrawl.powers.BufferPower;
import com.megacrit.cardcrawl.powers.NoDrawPower;
import com.megacrit.cardcrawl.vfx.combat.WeightyImpactEffect;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.enums.CardTagsEnum;

public class DoomPower extends AbstractPower {
    public static final String POWER_ID = InvincibleOneMod.makeID("DoomPower");
    private static final PowerStrings powerStrings = CardCrawlGame.languagePack.getPowerStrings(POWER_ID);
    public static final String NAME = powerStrings.NAME;
    public static final String[] DESC = powerStrings.DESCRIPTIONS;


    public DoomPower(AbstractCreature owner, int amount) {
        this.owner = owner;
        this.ID = POWER_ID;
        this.name = NAME;
        this.amount = amount;
        String path128 = InvincibleOneMod.getResourcePath("powers/128/Doom.png");
        String path48 = InvincibleOneMod.getResourcePath("powers/48/Doom.png");
        this.region128 = new TextureAtlas.AtlasRegion(ImageMaster.loadImage(path128), 0, 0, 84, 84);
        this.region48 = new TextureAtlas.AtlasRegion(ImageMaster.loadImage(path48), 0, 0, 32, 32);
        this.updateDescription();
        this.type = PowerType.BUFF;
        this.priority = 0;
    }

    public void updateDescription() {
        this.description = DESC[0];
    }

    @Override
    public void atStartOfTurn() {
        for (AbstractMonster m: AbstractDungeon.getCurrRoom().monsters.monsters) {
            if (!m.isDeadOrEscaped() && m.currentHealth < this.amount) {
                addToBot(new VFXAction(new WeightyImpactEffect(m.hb.cX, m.hb.cY)));
                if (m.hasPower(BufferPower.POWER_ID) && m.getPower(BufferPower.POWER_ID).amount > 0) {
                    if (m.getPower(BufferPower.POWER_ID).amount > 1) {
                        m.getPower(BufferPower.POWER_ID).amount--;
                    } else {
                        addToBot(new RemoveSpecificPowerAction(m, m, BufferPower.POWER_ID));
                    }
                } else {
                    m.currentHealth = 0;
                    m.healthBarRevivedEvent();
                    m.damage(new DamageInfo(null, 0, DamageInfo.DamageType.HP_LOSS));
                }
            }
        }
    }
}
